<template>
  <div class="body">
    <div class="left-board">
      <div class="logo">{{ title }}</div>
      <div class="operate">
        <!-- <el-button @click="goPreview" type="warning" plain>预览</el-button> -->
        <el-button @click="saveAll" type="primary" plain>保存</el-button>
        <!-- <el-button @click="publishAll" type="success" plain v-if="isTemplate == 0">发布</el-button> -->
        <!-- <el-button @click="clearAll" type="danger" plain>清空</el-button> -->
        <el-button type="info" plain @click="closeAll">关闭</el-button>
      </div>
    </div>
    <h3>评价人员</h3>
    <div class="center-board">
      <el-transfer v-model="rightValue" style="text-align: left; display: inline-block" filterable
        :titles="['人员名单', '评价人员']" :button-texts="['移除', '添加']" :data="teacherPageInfo.list"
        @change="handleChange">

        <template #default="{ option }">
          <span>{{ option.label }}</span>
        </template>
      </el-transfer>
    </div>
    <h3>评价学生</h3>
    <div class="center-board">
      <el-transfer v-model="rightValueStudent" style="text-align: left; display: inline-block" filterable
        :titles="['学生名单', '评价学生']" :button-texts="['移除', '添加']" :data="studetPageInfo.list"
        @change="handleChangeStudent">

        <template #default="{ option }">
          <span>{{ option.label }}</span>
        </template>
      </el-transfer>
    </div>
  </div>
</template>
<script >
import draggable from "vuedraggable";
import { ElMessage, ElMessageBox } from "element-plus";
import { Eleme, Delete, Remove, Plus, CopyDocument } from "@element-plus/icons-vue";

import { httpService } from "@/utils/httpService";

export default {
  name: "custom-clone",
  display: "Custom Clone",
  order: 3,
  mounted() {
    this.uuid = this.$route.query.p;
    this.queryById();
    this.queryAllRight();
    this.getBaseTeacherList();
    this.getStudentList();
  },

  watch: {

  },

  components: {
    draggable,
    Eleme,
    Delete, Remove,
    Plus,
    ElMessageBox,
    httpService,
    CopyDocument,
  },
  props: {
    value: {
      type: String,
      default: "",
    },
    disabled: {
      type: Boolean,
      default: false,
    },

  },
  data() {
    return {
      rightValue: [],
      rightValueStudent: [],
      list: [],
      teacherPageInfo: {},
      studetPageInfo: {},

      title: "",
      isTimeControl: 0,
      isPassword: 0,
      uuid: "",

      isEmpty: true,
      list: [],
      indexGlobal: -1,
      questionnaireId: 0,

    };
  },
  methods: {
    queryById() {
      httpService(
        "/javaApi/evReview/queryById",
        "id=" + this.uuid,
        "post"
      ).then((data) => {
        if (data != "") {
          this.title = data.title;
        } else {
          this.$router.push({
            path: "/noFound",
          });
        }
      });
    },
    queryByReviewId() {
      httpService(
        "/javaApi/evReviewQuestion/queryTree",
        "reviewId=" + this.uuid,
        "post"
      ).then((data) => {
        if (data) {
          this.list = data;
        } else {
          this.$router.push({
            path: "/noFound",
          });
        }
      });
    },
    getBaseTeacherList() {
      httpService(
        "/javaApi/baseTeacher/list/0/3000",
        {
        },
        "get"
      ).then((data) => {
        if (data.list) {
          for (let i = 0; i < data.list.length; i++) {
            data.list[i].key = data.list[i].teacherNumber;
            data.list[i].label = data.list[i].name;
            data.list[i].display = false;
          }
        }
        this.teacherPageInfo = data;
      });
    },
    getStudentList() {
      httpService(
        "/javaApi/baseStudent/list/0/30000",
        {
        },
        "get"
      ).then((data) => {
        if (data.list) {
          for (let i = 0; i < data.list.length; i++) {
            data.list[i].key = data.list[i].studentNumber;
            data.list[i].label =  data.list[i].clazzName+'-'+ data.list[i].name+'-'+data.list[i].title;
            data.list[i].display = false;
          }
        }
        this.studetPageInfo = data;
      });
    },
    queryAllRight() {
      httpService(
        "/javaApi/evUsers/queryAll",
        {
          reviewId:this.uuid
        },
        "get"
      ).then((data) => {
        if (data) {
          for (let i = 0; i < data.length; i++) {
            if(data[i].type==1){
              this.rightValue.push(data[i].userNumber)
            }else{
              this.rightValueStudent.push(data[i].userNumber)
            }
            
          }
        }
        this.studetPageInfo = data;
      });
    },

    // 可以添加一些自己的自定义事件，如清空内容
    clear() {
      this.contentValue = "";
    },



    //保存所有
    saveAll() {
      console.log("保存");
      if (this.rightValue.length > 0&&this.rightValueStudent.length>0) {
        let params = new FormData(); //创建一个form对象,必须是form对象否则后端接受不到数据
        params.append("teacherNumbers", this.rightValue);
        params.append("studentNumbers", this.rightValueStudent);
        params.append("id", this.uuid);
        httpService("/javaApi/evUsers/publish", params, "post", {
          "Content-Type": "application/x-www-form-urlencoded",
        }).then((data) => {
          if (data.code == 200) {
            // this.$router.replace({
            //   path: "/publishResult",
            //   query: { url: data.obj },
            // });
            ElMessage.success("保存成功");

          } else {
            ElMessage.error("发布失败，请重试！");
          }
        });
      } else {
        ElMessage.error("评价人员、评价学生，分别至少添加一人");

      }

    },

    handleChange(
      value,
      direction,
      movedKeys
    ) {
      console.log(value, direction, movedKeys)
    },
    handleChangeStudent(
      value,
      direction,
      movedKeys
    ) {
      console.log(value, direction, movedKeys)
    },

    closeAll() {
      ElMessageBox.confirm("已保存本次修改吗？确定关闭吗？", "提醒", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          window.opener = null;
          window.open("", "_self");
          window.close();
        })
        .catch(() => { });
    },


  },
};
</script>
<style>
.el-transfer-panel{
  width: 300px;
}
.el-tabs__content {
  border-left: 1px solid #dedede;
}

.el-tabs__item.is-active.is-focus {
  border: 0px solid red;
}

.el-rate__icon {
  font-size: 30px;
}

.el-tabs__header {
  padding: 0;
  position: relative;
  margin: 0 0 0px;
}

.el-radio {
  line-height: 32px;
}

.m-empty {
  background: url(../../assets/center_bg_2.png) no-repeat;
  background-repeat: no-repeat;
  background-position: center;
}

.el-switch__label span {
  line-height: 20px;
}

.el-switch {
  margin-left: 10px;
}

.el-divider {
  margin: 0px;
}
</style>
<style scoped>
.dateTimeRange {
  margin-bottom: 16px;
}

.mb-right {
  padding-left: 10px;
  padding-right: 10px;
  padding-bottom: 0px;
}

.ghost {
  border-top: 4px solid #409EFF;
}

.body {
  background: white;
  width: 90%;
  margin: 0 auto;
  padding-top: 20px;
  padding-bottom: 100px;
}

h3{
  color: #409EFF;
}
.delete-btn {
  margin-top: 10px;
}

.add-btn {
  margin-left: 80px;
}

.index {
  padding: 10px 10px 20px 0px;
  color: #409eff;
}

.m-line {
  background: #f2f2f2;
  height: 1px;
  margin-bottom: 10px;
}

.index-left {
  padding: 5px;
}

.delete {
  float: right;
  cursor: pointer;
  color: #f56c6c;
  padding: 5px;
  margin: 15px;
}

.delete-children {
  float: right;
  cursor: pointer;
}


.select-bg {
  border: 1px solid #409EFF;
  color: #606255;
  margin-top: 10px;
  background: white;
  border-radius: 4px;
}

.unselect-bg {
  border: 1px dashed #409EFF;
  background: white;
  margin-top: 10px;
  color: #606255;
  border-radius: 4px;
}

.list-group-item-right {
  cursor: move;
  /* display: flex; */
  padding: 20px;
}

.list-group-item-right:hover {
  background: white;
  border-radius: 6px;
}


.operate {
  font-weight: 600;
  height: 40px;
  line-height: 40px;
  float: right;
  text-align: right;
  font-size: 17px;
  padding-left: 20px;
  white-space: nowrap;
  background: white;
  padding-right: 20px;
}

.logo {
  color: #333333;
  font-weight: 600;
  height: 40px;
  line-height: 40px;
  font-size: 18px;
  padding-left: 10px;
  white-space: nowrap;
}

.logo-bottom {
  border-top: solid #dedede 1px;
  border-right: solid #dedede 1px;
  height: calc(100vh - 60px);
  padding: 10px;
}

.sub-title {
  text-align: right;
  vertical-align: middle;
  float: left;
  font-size: 14px;
  min-width: 100px;
  color: #606266;
  line-height: 40px;
  padding: 0 12px 0 0;
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
}

.list-group-item-left {
  cursor: move;
  width: 50%;
}

.list-group-item-left .components-item {
  display: inline-block;
  width: calc(100% - 8px);
  margin: 4px;
  -webkit-transition: -webkit-transform 0ms !important;
  transition: -webkit-transform 0ms !important;
  transition: transform 0ms !important;
  transition: transform 0ms, -webkit-transform 0ms !important;
}

.item {
  display: flex;
  width: 100%;
  flex-wrap: wrap;
}

.components-body:hover {
  border: 1px solid #409EFF;
  color: #409EFF;
}

.components-body {
  color: #707070;
  border: 1px solid #eaeaea;
  background-color: #fff;
  padding: 8px 10px;
  font-size: 16px;
  cursor: move;
  text-align: center;
  border-radius: 3px;
}

.components-title {
  font-size: 16px;
  color: #222;
  margin: 10px 2px;
  font-weight: bold;
}

.left-board {
}

.center-board {
  width: auto;
  background:white;
  text-align: center;
  padding: 20px;
  border-radius: 6px;
    opacity: 1;
    background: #FFFFFF;
    box-shadow: 0px 0px 4px 0px rgb(0 0 0 / 8%), 0px 2px 6px 0px rgb(0 0 0 / 6%), 0px 4px 8px 2px rgb(0 0 0 / 4%);
}

.draggable {
  height: calc(100vh - 80px);
  width: auto;

  overflow: scroll;
  border-top: 1px solid #dedede;
  padding: 10px 10px 30px 10px;
}


.right-content {
  width: calc(100% - 37px);
  height: calc(100vh - 60px);
  padding: 10px;
  overflow: auto;
}

.el-form-item--default {
  --font-size: 14px;
  --el-form-label-font-size: var(--font-size);
  margin-bottom: 18px;
  width: 100%;
}

.esign {
  max-width: 1000px;
  margin: auto;
  padding: 10px;
}

.esigh-btns button {
  color: #fff;
  height: 40px;
  width: 100px;
  font-size: 16px;
  margin-right: 10px;
  outline: none;
  border-radius: 4px;
  background: #f60;
  border: 1px solid transparent;
}

.esigh-btns button:active {
  color: #fff;
  box-shadow: 0px 0px 50px orangered inset;
}

.esigh-result {
  margin-top: 10px;
}

.esigh-result img {
  display: block;
  max-width: 100%;
  height: auto;
  border: 1px solid #ececee;
}

.esignature {
  margin: 10px 0;
  border: 1px solid #79bbff;
  border-radius: 4px;
}

.el-tabs__header {
  padding: 0;
  position: relative;
  margin: 0px;
}

.children-item {
  padding-left: 10px;
}

h3 {
  padding-left: 10px;
}

.demo-form-inline {
  display: flex;
}
</style>

